<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * addraid.php
 * Began: Mon December 23 2002
 * 
 * $Id: addraid.php 541 2008-05-20 06:56:16Z rspeicher $
 * 
 ******************************/
 
define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

$fv = new Form_Validate;

// Obtain var settings
$raid_id = ( !empty($_REQUEST[URI_RAID]) ) ? intval($_REQUEST[URI_RAID]) : '';
$confirm = ( !empty($_POST['confirm']) ) ? true : false;

// Start session management
$user->start();
$user->setup();

// Delete confirmation
// If they didn't confirm, redirect them to the last page they were on
if ( isset($_POST['cancel']) )
{
    if ( $raid_id )
    {
        $redirect = 'addraid.php'.$SID.'&' . URI_RAID . '='.$raid_id;
    }
    // They couldn't have been deleting something unless they provided a raid_id,
    // but anyway...
    else
    {
        $redirect = 'addraid.php'.$SID;
    }
    
    redirect($redirect);
}

// Figure out what submit button was pressed
$add    = ( isset($_POST['add']) ) ? true : false;
$update = ( isset($_POST['update']) ) ? true : false;
$delete = ( isset($_POST['delete']) ) ? true : false;

// Figure out action based on submit
if ( $add )
{
    $user->check_auth('a_raid_add');
    $action = 'add';
}
elseif ( $update )
{
    $user->check_auth('a_raid_upd');
    $action = 'update';
}
elseif ( ($delete) || ($confirm) )
{
    $user->check_auth('a_raid_del');
    $action = 'delete';
}
else
{
    $user->check_auth('a_raid_');
    $action = 'display';
}

//
// Error Checking and variable initialization
//
if ( ($add) || ($update) || ($delete) )
{
    $_POST = htmlspecialchars_array($_POST);
    
    $raid_added_by = $user->data['username'];
    $raid_updated_by = $user->data['username'];
    
    $fv->is_alpha('raid_attendees', $user->lang['fv_alpha_attendees']);
    $fv->is_filled(array(
        'raid_attendees' => $user->lang['fv_required_attendees'],
        'raid_name' => $user->lang['fv_required_event_name'])
    );
    $fv->is_within_range('mo', 1, 12, $user->lang['fv_range_month']);
    $fv->is_within_range('d', 1, 31, $user->lang['fv_range_day']);
    $fv->is_within_range('y', 1998, 2010, $user->lang['fv_range_year']); // How ambitious
    $fv->is_within_range('h', 0, 23, $user->lang['fv_range_hour']);
    $fv->is_within_range('mi', 0, 59, $user->lang['fv_range_minute']);
    $fv->is_within_range('s', 0, 59, $user->lang['fv_range_second']);
    if ( !empty($_POST['raid_value']) )
    {
        $fv->is_number('raid_value', $user->lang['fv_number_value']);
    }
    
    $raid_date = mktime($_POST['h'], $_POST['mi'], $_POST['s'], $_POST['mo'], $_POST['d'], $_POST['y']);
    $member_lastraid = $raid_date;
    
    // If there's errors, negate the whole thing since we'll need to re-display the form
    if ( $fv->is_error() )
    {
        $action = 'display';
    }
}

//
// Get relevant data
//
if ( $raid_id )
{
    $sql = 'SELECT raid_id, raid_name, raid_date, raid_note, raid_value
            FROM ' . RAIDS_TABLE . "
            WHERE raid_id='".$raid_id."'";
    $result = $db->query($sql);
    if ( !$row = $db->fetch_record($result) )
    {
        message_die($user->lang['error_invalid_raid_provided']);
    }
    $db->free_result($result);
    
    $current_time = $row['raid_date'];
    $raid = array(
        'raid_name' => post_or_db('raid_name', true, $row),
        'raid_note' => post_or_db('raid_note', true, $row),
        'raid_value' => post_or_db('raid_value', true, $row)
    );
    
    $sql = 'SELECT member_name
            FROM ' . RAID_ATTENDEES_TABLE . "
            WHERE raid_id='".$raid_id."'
            ORDER BY member_name";
    $result = $db->query($sql);
    while ( $arow = $db->fetch_record($result) )
    {
        $attendees[] = $arow['member_name'];
    }
    $raid['raid_attendees'] = ( !empty($_POST['raid_attendees']) ) ? $_POST['raid_attendees'] : implode(',', $attendees);
    unset($attendees);
}
else
{
    $current_time = time();
    $raid = array(
        'raid_date' => ( !$add ) ? $current_time : '',
        'raid_attendees' => post_or_db('raid_attendees', false),
        'raid_name' => post_or_db('raid_name', false),
        'raid_note' => post_or_db('raid_note', false),
        'raid_value' => post_or_db('raid_value', false)
    );
}

//
// Processing
//
switch ( $action )
{
    //
    // Add
    //
    case 'add':
        // Check if they entered a one-time value; Get the preset value of the raid if not
        if ( empty($_POST['raid_value']) )
        {
            $raid_value = $db->query_first('SELECT event_value FROM ' . EVENTS_TABLE . " WHERE event_name='".$_POST['raid_name']."'");
        }
        // Still no post value?
        if ( empty($raid_value) )
        {
            $raid_value = '0.00';
        }
        
        // Make sure that each member only appears once and sort the list alphabetically
        $raid_attendees = strtolower(preg_replace("/[[:space:]]/i", ' ', $_POST['raid_attendees']));
        $raid_attendees = ucwords($raid_attendees);
        
        $members_array = explode(' ', $raid_attendees);
        $members_array = array_unique($members_array);
        sort($members_array);
        reset($members_array);
        $members_count = count($members_array);
        
        session_start(); // Grab our array of name => class/level/race        
        for ( $i = 0; $i < $members_count; $i++ )
        {
            if ( !isset($members_array[$i]) )
            {
                continue;
            }
            
            // Get rid of any spaces
            $member_name = trim(str_replace(' ', '', $members_array[$i]));
            
            // Check if they exist in members_table already
            $sql = 'SELECT count(member_id) 
                    FROM ' . MEMBERS_TABLE . "
                    WHERE member_name='".$member_name."'";
                    
            // Check for race/class/level data for this member
            // The arrays are formed when we parse a log with the info.
            $member_level = ( isset($_SESSION[$member_name]['level']) ) ? $_SESSION[$member_name]['level'] : false;
            $member_race = ( isset($_SESSION[$member_name]['race']) ) ? $_SESSION[$member_name]['race'] : false;
            $member_class = ( isset($_SESSION[$member_name]['class']) ) ? $_SESSION[$member_name]['class'] : false;
            if ( isset($_SESSION[$member_name]) )
            {
                unset($_SESSION[$member_name]);
            }
            
            // The member doesn't exist yet, create them
            if ( ($db->query_first($sql) == 0) )
            {
                if ( trim($member_name) != '' )
                {
                    $sql = 'INSERT INTO ' . MEMBERS_TABLE . "
                            (member_id, member_name, member_earned, member_status, member_firstraid, member_lastraid, member_raidcount, 
                                member_level, member_race, member_class)
                            VALUES ('NULL','".remove_quote_escape($member_name)."','".remove_quote_escape($raid_value)."','1','".$member_lastraid."','".$member_lastraid."','1',
                                '".(( $member_level ) ? $member_level : 'NULL')."','".(( $member_race ) ? $member_race : 'NULL')."','".(( $member_class ) ? $member_class : 'NULL')."')";
                    $db->query($sql);
                }
            }
            // Member already exists, just update the earned
            else
            {
                // For each member_race/class/level, if it's set then we put it in quotes for a query
                // Otherwise we set it to the field name so it doesn't change what's already in there
                $member_level = ( is_numeric($member_level) ) ? '\''.$member_level.'\'' : 'member_level';
                $member_race  = ( is_string($member_race) ) ? '\''.$member_race.'\'' : 'member_race';
                $member_class = ( is_string($member_class) ) ? '\''.$member_class.'\'' : 'member_class';
                
                $sql = 'UPDATE ' . MEMBERS_TABLE . '
                        SET member_earned = member_earned+'.$raid_value.", member_lastraid='".$member_lastraid."', member_raidcount = member_raidcount+1, 
                            member_level=".$member_level.", member_race=".$member_race.", member_class=".$member_class."
                        WHERE member_name='".$member_name."'";
                $db->query($sql);
            }
        }
        session_destroy();
        
        // Insert the raid
        $sql = 'INSERT INTO ' . RAIDS_TABLE . "
                (raid_id, raid_name, raid_date, raid_note, raid_value, raid_added_by)
                VALUES ('NULL','".remove_quote_escape($_POST['raid_name'])."','".$raid_date."','".remove_quote_escape($_POST['raid_note'])."','".$raid_value."','".$raid_added_by."')";
        $db->query($sql);
        
        $this_raid_id = $db->insert_id();

        // Attendees management
        // Get rid of the 'blank' member bug
        $raid_attendees = implode(',', $members_array);
        $raid_attendees = preg_replace("/^\,(.{1,})/", "\\1", $raid_attendees);
        $members_array = explode(',', $raid_attendees);
        $members_count = sizeof($members_array);

        for ( $i = 0; $i < $members_count; $i++ )
        {
            $sql = 'INSERT INTO ' . RAID_ATTENDEES_TABLE . "
                    (raid_id, member_name)
                    VALUES ('".$this_raid_id."','".$members_array[$i]."')";
            $db->query($sql);
        }
        
        // Logging
        $log_action = array(
            'header' => '{L_ACTION_RAID_ADDED}',
            'id' => $this_raid_id,
            '{L_EVENT}' => $_POST['raid_name'],
            '{L_ATTENDEES}' => implode(', ', $members_array),
            '{L_NOTE}' => $_POST['raid_note'],
            '{L_VALUE}' => $raid_value,
            '{L_ADDED_BY}' => $raid_added_by);
        $eqdkp->log_insert(array(
            'log_type' => $log_action['header'],
            'log_action' => $eqdkp->make_log_action($log_action),
            'log_ipaddress' => $user->ip,
            'log_sid' => $user->session_id,
            'log_result' => '{L_SUCCESS}',
            'admin_id' => $user->data['user_id'])
        );
        
        $success_message = sprintf($user->lang['admin_add_raid_success'], $_POST['mo'], $_POST['d'], $_POST['y'], $_POST['raid_name']);
        if ( $eqdkp->config['hide_inactive'] == 1 )
        {
            $success_message .= '<br /><br />'.$user->lang['admin_add_raid_success_hideinactive'];
            if ( update_player_status() )
            {
                $success_message .= ' '.strtolower($user->lang['done']);
            }
            else
            {
                $success_message .= ' '.strtolower($user->lang['error']);
            }
        }
        
        $link_list = generate_admin_success_links(array(
            $user->lang['add_items_from_raid'] => 'additem.php'.$SID.'&amp;raid_id='.$this_raid_id,
            $user->lang['add_raid'] => 'addraid.php'.$SID,
            $user->lang['list_raids'] => 'listraids.php'.$SID)
        );
        
        message_die(stripslashes($success_message) . '<br /><br />' . $link_list);
        
        break;
    //
    // Update
    //
    case 'update':
        // Get the 'old' data so we can see what's been changed
        $sql = 'SELECT raid_name, raid_value, raid_note
                FROM ' . RAIDS_TABLE . "
                WHERE raid_id='".$raid_id."'";
        $result = $db->query($sql);
        while ( $row = $db->fetch_record($result) )
        {
            $old_raid = array(
                'raid_name' => addslashes($row['raid_name']),
                'raid_value' => addslashes($row['raid_value']),
                'raid_note' => addslashes($row['raid_note'])
            );
        }
        $db->free_result($result);
        
        $sql = 'SELECT member_name
                FROM ' . RAID_ATTENDEES_TABLE . "
                WHERE raid_id='".$raid_id."'
                ORDER BY member_name";
        $result = $db->query($sql);
        while ( $arow = $db->fetch_record($result) )
        {
            $attendees[] = $arow['member_name'];
        }
        $old_raid['raid_attendees'] = @implode(',', $attendees);
        unset($attendees);
        
        // Now 'undo' the old raid that's being updated
        // Take the old value away from the old attendees
        $members_array = explode(',', $old_raid['raid_attendees']);
        $members_array_count = sizeof($members_array);
        
        // Remove the attendees of the 'old' raid
        $db->query('DELETE FROM ' . RAID_ATTENDEES_TABLE . " WHERE raid_id='".$raid_id."'");
        
        if ( empty($_POST['raid_value']) )
        {
            $raid_value = $db->query_first('SELECT event_value FROM ' . EVENTS_TABLE . " WHERE event_name='".$_POST['raid_name']."'");
        }
        if ( empty($raid_value) )
        {
            $raid_value = '0.00';
        }
        
        for ( $i = 0; $i < $members_array_count; $i++ )
        {
            if ( !isset($members_array[$i]) )
            {
                continue;
            }
            
            // Remove the value of the old raid from their earned
            $sql = 'UPDATE ' . MEMBERS_TABLE . "
                    SET member_earned = member_earned-".$old_raid['raid_value'].", member_raidcount = member_raidcount-1 
                    WHERE member_name='".$members_array[$i]."'";
            $db->query($sql);
        }
        
        // Now add the new, updated raid to their earned
        $raid_attendees = strtolower(preg_replace("/[[:space:]]/i", ' ', $_POST['raid_attendees']));
        $raid_attendees = ucwords($raid_attendees);
        
        // 'N' as in 'new' - keep the two arrays separate
        $n_members_array = explode(' ', $raid_attendees);
        $n_members_array = array_unique($n_members_array);
        sort($n_members_array);
        reset($n_members_array);
        $n_members_count = count($n_members_array);
        
        session_start();
        for ( $i = 0; $i < $n_members_count; $i++ )
        {
            if ( !isset($n_members_array[$i]) )
            {
                continue;
            }
            
            // Get rid of any spaces
            $member_name = trim(str_replace(' ', '', $n_members_array[$i]));
            
            // Check if they exist in members_table already
            $sql = 'SELECT count(member_id) 
                    FROM ' . MEMBERS_TABLE . "
                    WHERE member_name='".$member_name."'";
                    
            // Check for race/class/level data for this member
            // The arrays are formed when we parse a log with the info.
            $member_level = ( isset($_SESSION[$member_name]['level']) ) ? $_SESSION[$member_name]['level'] : false;
            $member_race = ( isset($_SESSION[$member_name]['race']) ) ? $_SESSION[$member_name]['race'] : false;
            $member_class = ( isset($_SESSION[$member_name]['class']) ) ? $_SESSION[$member_name]['class'] : false;
            if ( isset($_SESSION[$member_name]) )
            {
                unset($_SESSION[$member_name]);
            }
            
            // The member doesn't exist yet, create them
            if ( ($db->query_first($sql) == 0) )
            {
                if ( trim($member_name) != '' )
                {
                    $sql = 'INSERT INTO ' . MEMBERS_TABLE . "
                            (member_id, member_name, member_earned, member_status, member_firstraid, member_lastraid, member_raidcount, 
                                member_level, member_race, member_class)
                            VALUES ('NULL','".remove_quote_escape($member_name)."','".remove_quote_escape($raid_value)."','1','".$member_lastraid."','".$member_lastraid."','1',
                                '".(( $member_level ) ? $member_level : 'NULL')."','".(( $member_race ) ? $member_race : 'NULL')."','".(( $member_class ) ? $member_class : 'NULL')."')";
                    $db->query($sql);
                }
            }
            // Member already exists, just update the earned
            else
            {
                // For each member_race/class/level, if it's set then we put it in quotes for a query
                // Otherwise we set it to the field name so it doesn't change what's already in there
                $member_level = ( is_numeric($member_level) ) ? '\''.$member_level.'\'' : 'member_level';
                $member_race  = ( is_string($member_race) ) ? '\''.$member_race.'\'' : 'member_race';
                $member_class = ( is_string($member_class) ) ? '\''.$member_class.'\'' : 'member_class';
                
                $sql = 'UPDATE ' . MEMBERS_TABLE . '
                        SET member_earned = member_earned+'.$raid_value.", member_lastraid='".$member_lastraid."', member_raidcount = member_raidcount+1,
                            member_level=".$member_level.", member_race=".$member_race.", member_class=".$member_class." 
                        WHERE member_name='".$member_name."'";
                $db->query($sql);
            }
        }
        session_destroy();
        
        // Update the raid
        $sql = 'UPDATE ' . RAIDS_TABLE . "
                SET raid_date='".$raid_date."', raid_note='".remove_quote_escape($_POST['raid_note'])."', raid_value='".$raid_value."', 
                raid_name='".remove_quote_escape($_POST['raid_name'])."', raid_updated_by='".$raid_updated_by."'
                WHERE raid_id='".$raid_id."'";
        $db->query($sql);
        
        // Attendees management
        // Get rid of the 'blank' member bug
        $raid_attendees = implode(',', $n_members_array);
        $raid_attendees = preg_replace("/^\,(.{1,})/", "\\1", $raid_attendees);
        $n_members_array = explode(',', $raid_attendees);
        $n_members_count = sizeof($n_members_array);
        
        for ( $i = 0; $i < $n_members_count; $i++ )
        {
            $sql = 'INSERT INTO ' . RAID_ATTENDEES_TABLE . "
                    (raid_id, member_name)
                    VALUES ('".$raid_id."','".$n_members_array[$i]."')";
            $db->query($sql);
        }
        
        // Logging
        $old_attendees_array = explode(',', $old_raid['raid_attendees']);
        $new_attendees_array = $n_members_array;
        
        $log_action = array(
            'header' => '{L_ACTION_RAID_UPDATED}',
            'id' => $raid_id,
            '{L_EVENT_BEFORE}' => $old_raid['raid_name'],
            '{L_ATTENDEES_BEFORE}' => implode(', ', find_difference($new_attendees_array, $old_attendees_array)),
            '{L_NOTE_BEFORE}' => $old_raid['raid_note'],
            '{L_VALUE_BEFORE}' => $old_raid['raid_value'],
            '{L_EVENT_AFTER}' => find_difference($old_raid['raid_name'], $_POST['raid_name']),
            '{L_ATTENDEES_AFTER}' => implode(', ', find_difference($old_attendees_array, $new_attendees_array)),
            '{L_NOTE_AFTER}' => find_difference($old_raid['raid_note'], $_POST['raid_note']),
            '{L_VALUE_AFTER}' => find_difference($old_raid['raid_value'], $raid_value),
            '{L_UPDATED_BY}' => $raid_updated_by);
        $eqdkp->log_insert(array(
            'log_type' => $log_action['header'],
            'log_action' => $eqdkp->make_log_action($log_action),
            'log_ipaddress' => $user->ip,
            'log_sid' => $user->session_id,
            'log_result' => '{L_SUCCESS}',
            'admin_id' => $user->data['user_id'])
        );
        
        $success_message = sprintf($user->lang['admin_update_raid_success'], $_POST['mo'], $_POST['d'], $_POST['y'], $_POST['raid_name']);
        $link_list = generate_admin_success_links(array(
            $user->lang['add_items_from_raid'] => 'additem.php'.$SID.'&amp;raid_id='.$raid_id,
            $user->lang['add_raid'] => 'addraid.php'.$SID,
            $user->lang['list_raids'] => 'listraids.php'.$SID)
        );
        
        message_die(stripslashes($success_message) . '<br /><br />' . $link_list);
        
        break;
    //
    // Delete
    //
    case 'delete':
        if ( !$confirm )
        {
            confirm_delete($user->lang['confirm_delete_raid'], URI_RAID, $raid_id, 'addraid.php'.$SID);
        }
        else
        {
            // Get the 'old' data so we can see what's been changed
            $sql = 'SELECT raid_name, raid_value, raid_note
                    FROM ' . RAIDS_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $result = $db->query($sql);
            while ( $row = $db->fetch_record($result) )
            {
                $old_raid = array(
                    'raid_name' => addslashes($row['raid_name']),
                    'raid_value' => addslashes($row['raid_value']),
                    'raid_note' => addslashes($row['raid_note'])
                );
            }
            $db->free_result($result);
            
            $sql = 'SELECT member_name
                    FROM ' . RAID_ATTENDEES_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $result = $db->query($sql);
            while ( $arow = $db->fetch_record($result) )
            {
                $attendees[] = $arow['member_name'];
            }
            $old_raid['raid_attendees'] = implode(',', $attendees);
            unset($attendees);
           
            // Now 'undo' the old raid that's being updated
            // Take the old value away from the old attendees
            $members_array = explode(',', $old_raid['raid_attendees']);
            $members_array_count = sizeof($members_array);
            
            $raid_value = $old_raid['raid_value'];
            
            for ( $i = 0; $i < $members_array_count; $i++ )
            {
                // Remove the value of the old raid from their earned
                $sql = 'UPDATE ' . MEMBERS_TABLE . "
                        SET member_earned = member_earned-".$old_raid['raid_value'].", member_raidcount = member_raidcount-1 
                        WHERE member_name='".$members_array[$i]."'";
                $db->query($sql);
            }
            
            // Remove any items associated with the raid; remove the charge from the buyers
            $sql = 'SELECT item_id, item_buyer, item_value
                    FROM ' . ITEMS_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $result = $db->query($sql);
            while ( $item = $db->fetch_record($result) )
            {
                $item_value = ( !empty($item['item_value']) ) ? $item['item_value'] : '0.00';
                $sql = 'UPDATE ' . MEMBERS_TABLE ."
                        SET member_spent = member_spent-".$item_value." WHERE member_name='".$item['item_buyer']."'";
                $db->query($sql);
            }
            
            // Delete associated items 
            $db->free_result($result);
            $sql = 'DELETE FROM ' . ITEMS_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $db->query($sql);
            
            // Delete attendees
            $sql = 'DELETE FROM ' . RAID_ATTENDEES_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $db->query($sql);
            
            // Remove the raid itself
            $sql = 'DELETE FROM ' . RAIDS_TABLE . "
                    WHERE raid_id='".$raid_id."'";
            $db->query($sql);
            
            // Logging
            $log_action = array(
                'header' => '{L_ACTION_RAID_DELETED}',
                'id' => $raid_id,
                '{L_EVENT}' => $old_raid['raid_name'],
                '{L_ATTENDEES}' => str_replace(',', ', ', $old_raid['raid_attendees']),
                '{L_NOTE}' => $old_raid['raid_note'],
                '{L_VALUE}' => $raid_value);
            $eqdkp->log_insert(array(
                'log_type' => $log_action['header'],
                'log_action' => $eqdkp->make_log_action($log_action),
                'log_ipaddress' => $user->ip,
                'log_sid' => $user->session_id,
                'log_result' => '{L_SUCCESS}',
                'admin_id' => $user->data['user_id'])
            );
            
            $success_message = $user->lang['admin_delete_raid_success'];
            $link_list = generate_admin_success_links(array(
                $user->lang['add_raid'] => 'addraid.php'.$SID,
                $user->lang['list_raids'] => 'listraids.php'.$SID)
            );
            
            message_die(stripslashes($success_message) . '<br /><br />' . $link_list);
            
        } // confirmed
        break;
    //
    // Display form
    //
    case 'display':
        // Find the value of the event, or use the one-time value from the form
        $preset_value = $db->query_first('SELECT event_value FROM ' . EVENTS_TABLE . " WHERE event_name='".addslashes($raid['raid_name'])."'");
        $raid_value = ( $raid['raid_value'] == 0 ) ? '' : $raid['raid_value'];
        $raid_value = ( $raid['raid_value'] == $preset_value ) ? '' : $raid['raid_value'];
        
        // Build event drop-down
        $max_value = $db->query_first('SELECT max(event_value) FROM ' . EVENTS_TABLE);
        $float = @explode('.', $max_value);
        $format = '%0' . @strlen($float[0]) . '.2f';
        
        $sql = 'SELECT event_id, event_name, event_value
                FROM ' . EVENTS_TABLE . '
                ORDER BY event_name';
        $events_result = $db->query($sql);
        while ( $event = $db->fetch_record($events_result) )
        {
            $tpl->assign_block_vars('events_row', array(
                'VALUE' => stripslashes($event['event_name']),
                'SELECTED' => ( $event['event_name'] == $raid['raid_name'] ) ? ' selected="selected"' : '',
                'OPTION' => '(' . sprintf($format, $event['event_value']) . ') - ' . stripslashes($event['event_name']))
            );
        }
        $db->free_result($events_result);
        
        $tpl->assign_vars(array(
            'F_ADD_RAID' => 'addraid.php'.$SID,
            'RAID_ID' => $raid_id,
            
            'U_ADD_EVENT' => 'addevent.php'.$SID,
            
            'RAID_ATTENDEES' => str_replace(',', "\n", $raid['raid_attendees']),
            'RAID_VALUE' => stripslashes($raid_value),
            'RAID_NOTE' => stripslashes($raid['raid_note']),
            'MO' => date('m', stripslashes($current_time)),
            'D' => date('d', stripslashes($current_time)),
            'Y' => date('Y', stripslashes($current_time)),
            'H' => date('h', stripslashes($current_time)),
            'MI' => date('i', stripslashes($current_time)),
            'S' => date('s', stripslashes($current_time)),
            
            'L_ADD_RAID_TITLE' => $user->lang['addraid_title'],
            'L_ATTENDEES' => $user->lang['attendees'],
            'L_PARSE_LOG_BUTTON_TEXT' => $user->lang['parse_log_button_text'],
            'L_EVENT' => $user->lang['event'],
            'L_ADD_EVENT' => $user->lang['add_event'],
            'L_VALUE' => $user->lang['value'],
            'L_ADDRAID_VALUE_NOTE' => $user->lang['addraid_value_note'],
            'L_DATE' => $user->lang['date'],
            'L_TIME' => $user->lang['time'],
            'L_ADDRAID_DATETIME_NOTE' => $user->lang['addraid_datetime_note'],
            'L_NOTE' => $user->lang['note'],
            'L_ADD_RAID' => $user->lang['add_raid'],
            'L_RESET' => $user->lang['reset'],
            'L_UPDATE_RAID' => $user->lang['update_raid'],
            'L_DELETE_RAID' => $user->lang['delete_raid'],
            
            'FV_ATTENDEES' => $fv->generate_error('raid_attendees'),
            'FV_EVENT_NAME' => $fv->generate_error('raid_name'),
            'FV_VALUE' => $fv->generate_error('raid_value'),
            'FV_MO' => $fv->generate_error('mo'),
            'FV_D' => $fv->generate_error('d'),
            'FV_Y' => $fv->generate_error('y'),
            'FV_H' => $fv->generate_error('h'),
            'FV_MI' => $fv->generate_error('mi'),
            'FV_S' => $fv->generate_error('s'),
            
            'MSG_ATTENDEES_EMPTY' => $user->lang['fv_required_attendees'],
            'MSG_NAME_EMPTY' => $user->lang['fv_required_event_name'],
            
            'S_PARSE_LOG_BUTTON' => true,
            'S_ADD' => ( !$raid_id ) ? true : false)
        );
        
        $page_title = sprintf($user->lang['admin_title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['addraid_title'];
        include_once($eqdkp_root_path . 'includes/page_header.php');
        
        $tpl->set_filenames(array(
            'body' => 'admin/addraid.html')
        );
        
        include_once($eqdkp_root_path . 'includes/page_tail.php');
        break;
} // Processing
?>